package com.changgou.kafka;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class kafkaList {

    @KafkaListener(topics = "test03")  // 支持监听多个topic的消息
    public void consumerMessage(ConsumerRecord<String, String> consumerRecord, Acknowledgment ack) {
        try {
            String value = consumerRecord.value();
            // 业务处理......
            System.out.println("收到得消息为"+value);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            ack.acknowledge();
        }
    }
}
